﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace DialogForm
{
    public partial class FrmOutStock_dlg : XtraForm
    {
        public FrmOutStock_dlg()
        {
            InitializeComponent();
            InitGrid();
        }

        public delegate void ReturnIDEventHandler(long ID);
        public event ReturnIDEventHandler ReturnID;

        private void FrmPurchaseOrder_dlg_Load(object sender, EventArgs e)
        {
            LoadData();
        }

        private void LoadData()
        {
            var code = txtCode.Text.Trim();
            var status = cbbStatus.SelectedIndex;
            var date = cbbDate.SelectedIndex;

            var bll = new DMZS.BLL.OutStock();
            var ds = bll.GetListForDialog(code, status, date);
            if (ds != null)
            {
                grdBody.DataSource = ds.Tables[0];
            }
        }

        /// <summary>
        /// 初始网格显示
        /// </summary>
        private void InitGrid()
        {
            grvBody.IndicatorWidth = grvBody.IndicatorWidth == -1 ? 40 : grvBody.IndicatorWidth;
            grvBody.OptionsView.ShowIndicator = true;

            CommonControl.DxGridHelper.InitGridStyle(grvBody);
        }

        private void grdBody_DoubleClick(object sender, EventArgs e)
        {
            
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            if (grvBody.GetFocusedDataRow() == null)
            {
                XtraMessageBox.Show("没有数据。", Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                return;
            }

            ReturnID(Convert.ToInt64(grvBody.GetFocusedDataRow()["Vchcode"]));
            Close();
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            LoadData();
        }

        private void grvBody_DoubleClick(object sender, EventArgs e)
        {
            if (grvBody.GetFocusedDataRow() == null)
            {
                XtraMessageBox.Show("没有数据。", Text, MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
                return;
            }

            ReturnID(Convert.ToInt64(grvBody.GetFocusedDataRow()["Vchcode"]));
            Close();
        }

        private void grvBody_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
        {
            CommonControl.DxGridHelper.DrawRowIndicator(sender, e);
        }
    }
}
